package cn.ddiancan.xddcloud.ddccore.config;

import cn.ddiancan.xddcloud.common.context.XddCloudContextUtils;
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableKnife4j
public class OpenApiConfiguration {

    @Value("${xddcloud.base.swagger.title:星点点整合微服务Api}")
    private String title;

    @Value("${xddcloud.base.swagger.description:星点点整合微服务Api}")
    private String description;

    @Value("${xddcloud.base.swagger.owner:Amos}")
    private String owner;

    @Value("${xddcloud.base.swagger.url:https://ddcx.91dcan.cn/#/index}")
    private String url;

    @Value("${xddcloud.base.swagger.email:lupx@ddiancan.cn}")
    private String email;

    @Bean
    public OpenAPI docket() {
        return new OpenAPI().info(new Info().title(title).description(description).version("v1")
            .contact(new Contact().email(email).url(url).name(owner))
            .license(new License().name("Apache 2.0").url("http://springdoc.org")));
    }

    @Bean
    public GroupedOpenApi userApi() {
        return GroupedOpenApi.builder().group(XddCloudContextUtils.getApplication())
            .displayName(XddCloudContextUtils.getApplication()).pathsToMatch("/**") // 根据你的实际路径进行配置
            .build();
    }
}
